package com.day12.study.chat;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端
 *
 * @author Twinkle
 */
public class Client {
    public static void main(String[] args) {
        Socket socket = null;
        Scanner sc = new Scanner(System.in);
        try {
            socket = new Socket("127.0.0.1", 8888);
            //专门用于读取返回的数据
            new Thread(new ClientThread(socket)).start();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            OutputStream os = socket.getOutputStream();
            DataOutputStream dos = new DataOutputStream(os);
            String sendMsg = null;
            do {
                sendMsg = sc.nextLine();
                dos.writeUTF(sendMsg);
            } while (!"再见".equals(sendMsg));
            dos.close();
            socket.close();
            sc.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
